package com.ruitu.health.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health.fragment.Home3Fragment;
import com.ruitu.health.mvp.model.HomeModel;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.home.HomeData;
import com.ruitu.router_module.bean.home.ReadPartie;
import com.ruitu.router_module.bean.product.ArtiVideo;
import com.ruitu.router_module.bean.product.ProHome;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class HomePresenter {

    public static class HomeP extends BasePresenter<Home3Fragment, HomeModel.HomeM> {
        public Disposable reqHomeData() {
            return m.reqHomeFata().subscribe(new Consumer<BaseResult2<HomeData>>() {
                @Override
                public void accept(BaseResult2<HomeData> baseResult2) throws Exception {
                    v.hideProgress();
                    if (baseResult2.isSuccess()) {
                        v.onReqComplete(1, true, baseResult2.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult2.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    ToastUtils.showShortSafe("初始化首页失败");
                    throwable.printStackTrace();
                }
            });
        }

        public Disposable reqHomeTab1(String tabId, int size, int num) {
            return m.reqHomeTab1(tabId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<ProHome>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<ProHome>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(11, true, pageResult.getData());
                    } else {
                        ToastUtils.showShortSafe(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }

        public Disposable reqHomeTab2(String tabId, int size, int num) {
            return m.reqHomeTab2(tabId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<ReadPartie>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<ReadPartie>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(12, true, pageResult.getData());
                    } else {
                        ToastUtils.showShortSafe(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }

        public Disposable reqHomeTab3(String tabId, int size, int num) {
            return m.reqHomeTab3(tabId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<ArtiVideo>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<ArtiVideo>> pageResult) throws Exception {
                    v.hideProgress();
                    if (pageResult.isSuccess()) {
                        v.onReqComplete(13, true, pageResult.getData());
                    } else {
                        ToastUtils.showShortSafe(pageResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }
}
